local skel = fk.CreateSkill {
  name = "lb__zhangfu",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lb__zhangfu"] = "涨幅",
  --[":lb__zhangfu"] = "<b>锁定技</b>，你没有判定与弃牌阶段，你于你的每个阶段至多可使用一张牌。你可于每个阶段开始时使用一张牌，你的回合结束时，若你于所有阶段均使用了牌且牌名均不同，你摸两张牌。",
  --9.23
  [":lb__zhangfu"] = "<b>锁定技</b>，你没有判定与弃牌阶段，你于你的每个阶段至多可使用一张牌。你可于每个阶段开始时使用一张牌，你的回合结束时，若你于至少三个阶段均使用了牌名不同的牌，你摸两张牌。",
  
  ["#lb__zhangfu"] = "涨幅：%arg开始时，你可以使用一张牌",

  ["$lb__zhangfu1"] = "开始吧，资产评估。",
  ["$lb__zhangfu2"] = "行情扑朔迷离",
  ["$lb__zhangfu3"] = "这个项目就算结了。",
}

skel:addEffect(fk.TurnEnd, {
  audio_index = 3,
  anim_type = "drawcard",
  --[[
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      local chong = true --牌名重复就为假
      local card_name = {}
      local use_card = 0
      local n = #player.room.logic:getEventsOfScope(GameEvent.Phase, 999, function(e)
        if chong and e.data.who == player and table.contains({ Player.Start, Player.Draw, Player.Play, Player.Finish }, e.data.phase) then
          if chong and #e:searchEvents(GameEvent.UseCard, 999, function(u)
                local use = u.data
                if chong and use.from == player then
                  if table.contains(card_name, use.card.trueName) then
                    chong = false
                  else
                    table.insert(card_name, use.card.trueName)
                  end
                  return chong
                end
              end) > 0 then
            use_card = use_card + 1
          end
          return chong
        end
      end, Player.HistoryTurn)
      return chong and n == use_card
    end
  end,
  --]]
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      local card_name = {}
      return #player.room.logic:getEventsOfScope(GameEvent.Phase, 3, function(e)
        if e.data.who == player and table.contains({ Player.Start, Player.Draw, Player.Play, Player.Finish }, e.data.phase) then
          return #e:searchEvents(GameEvent.UseCard, 999, function(u)
            local use = u.data
            if use.from == player then
              table.insertIfNeed(card_name, use.card.trueName)
              return true
            end
          end) > 0
        end
      end, Player.HistoryTurn) == 3 and #card_name > 2
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, skel.name)
  end,
})

skel:addEffect(fk.EventPhaseChanging, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
    table.contains({ Player.Judge, Player.Discard }, data.phase)
  end,
  on_use = function(self, event, target, player, data)
    data.skipped = true
  end,
})

skel:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase ~= Player.NotActive
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "lb__zhangfu-phase", 1)
    player:endPlayPhase()
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
        table.contains({ Player.Start, Player.Draw, Player.Play, Player.Finish }, player.phase)
  end,
  on_cost = function(self, event, target, player, data)
    local use = player.room:askToPlayCard(player, {
      skill_name = "lb__zhangfu",
      skip = true,
      prompt = "#lb__zhangfu:::" .. Util.PhaseStrMapper(player.phase),
    })
    event:setCostData(self, { u = use })
    return use
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(skel.name, math.random(1, 2))
    player.room:notifySkillInvoked(player, skel.name)
    player.room:useCard(event:getCostData(self).u)
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return player:getMark("lb__zhangfu-phase") > 0
  end,
})

return skel
